//
//  UIBarButtonItem+Extensions.swift
//  Timor微博
//
//  Created by 周周旗 on 2019/2/27.
//  Copyright © 2019 ZQ. All rights reserved.
//

import UIKit

extension UIBarButtonItem{
    
    /// 创建 UIBarButtonItem
    ///
    /// - Parameters:
    ///   - title: title
    ///   - fontSize: fontSize 默认字号16
    ///   - target: target
    ///   - action: action
    ///   - action: isBackItem 判断是不是back
    /// - convenience: 遍历构造函数
    
    convenience init(title:String ,fontSize:CGFloat = 16,target:Any,action:Selector,isBackItem:Bool = false) {
        let btn :UIButton = UIButton.cz_textButton(title, fontSize: fontSize, normalColor: UIColor.darkText, highlightedColor: UIColor.orange)
        if isBackItem {
            let imageName = "navigationbar_back_withtext"
            btn.setImage(UIImage(named: imageName), for: .normal)
            btn.setImage(UIImage(named: imageName + "_highlighted"), for: .highlighted)
            
            btn.sizeToFit()
        }
        btn.addTarget(target, action: action, for: .touchUpInside)
        
        // self.init 实例化 UIBarButtonItem
        self.init(customView: btn)
    }
}
